<?php

/**
 * This is the model class for table "{{sensors}}".
 *
 * The followings are the available columns in table '{{sensors}}':
 * @property integer $RECORD_ID
 * @property string $SENSORNAME_V
 * @property string $GROUPNAME_V
 * @property string $BASENAME_V
 * @property string $PROVINCENAME_V
 * @property string $CITYNAME_V
 * @property string $COUNTRYNAME_V
 * @property string $SENSOR_SETUP_NAME_V
 * @property integer $SENSOR_N
 * @property integer $BATTERYNUM_N
 * @property integer $SENSOR_ADDR_N
 * @property integer $COM_N
 * @property string $IP_V
 * @property string $SETUP_D
 * @property string $REMARK_V
 */
class Sensors extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return Sensors the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return '{{sensors}}';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('SENSOR_N, BATTERYNUM_N, SENSOR_ADDR_N, COM_N', 'numerical', 'integerOnly'=>true),
			array('SENSORNAME_V, GROUPNAME_V, BASENAME_V, PROVINCENAME_V, CITYNAME_V, COUNTRYNAME_V, SENSOR_SETUP_NAME_V, IP_V, REMARK_V', 'length', 'max'=>255),
			array('SETUP_D', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('RECORD_ID, SENSORNAME_V, GROUPNAME_V, BASENAME_V, PROVINCENAME_V, CITYNAME_V, COUNTRYNAME_V, SENSOR_SETUP_NAME_V, SENSOR_N, BATTERYNUM_N, SENSOR_ADDR_N, COM_N, IP_V, SETUP_D, REMARK_V', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'BTBATTERYS'=>array(self::BELONGS_TO, 'BtBatterys', 'GROUPNAME_V'),
			'MTSYSBASE'=>array(self::BELONGS_TO, 'MtsysBase', 'BASENAME_V'),				
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'RECORD_ID' => '流水',
			'SENSORNAME_V' => '传感器名称',
			'GROUPNAME_V' => '电池组名称',
			'BASENAME_V' => '站点名称',
			'PROVINCENAME_V' => '省份',
			'CITYNAME_V' => '城市',
			'COUNTRYNAME_V' => '县',
			'SENSOR_SETUP_NAME_V' => '传感器安装地址',
			'SENSOR_N' => '传感器编号',
			'BATTERYNUM_N' => '电池节数',
			'SENSOR_ADDR_N' => '传感器设备地址',
			'COM_N' => '串口号',
			'IP_V' => 'IP地址',
			'SETUP_D' => '创建时间',
			'REMARK_V' => '备注',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('RECORD_ID',$this->RECORD_ID);
		$criteria->compare('SENSORNAME_V',$this->SENSORNAME_V,true);
		$criteria->compare('GROUPNAME_V',$this->GROUPNAME_V,true);
		$criteria->compare('BASENAME_V',$this->BASENAME_V,true);
		$criteria->compare('PROVINCENAME_V',$this->PROVINCENAME_V,true);
		$criteria->compare('CITYNAME_V',$this->CITYNAME_V,true);
		$criteria->compare('COUNTRYNAME_V',$this->COUNTRYNAME_V,true);
		$criteria->compare('SENSOR_SETUP_NAME_V',$this->SENSOR_SETUP_NAME_V,true);
		$criteria->compare('SENSOR_N',$this->SENSOR_N);
		$criteria->compare('BATTERYNUM_N',$this->BATTERYNUM_N);
		$criteria->compare('SENSOR_ADDR_N',$this->SENSOR_ADDR_N);
		$criteria->compare('COM_N',$this->COM_N);
		$criteria->compare('IP_V',$this->IP_V,true);
		$criteria->compare('SETUP_D',$this->SETUP_D,true);
		$criteria->compare('REMARK_V',$this->REMARK_V,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}